/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConfirmPanel.java
 *
 * Created on Jul 12, 2012, 2:09:27 PM
 */

package com.piza.toolcenter.view.mybatis;

import com.piza.toolcenter.operation.IWorkFlow;
import com.piza.toolcenter.operation.OperationTree;
import com.piza.toolcenter.operation.SessionContext;

/**
 *
 * @author cwb
 */
public class ConfirmPanel extends javax.swing.JPanel implements IWorkFlow{

    private SessionContext context;
    /** Creates new form ConfirmPanel */
    public ConfirmPanel() {
        initComponents();
    }

    public void open(SessionContext context) {
      this.context=context; 
        String generateConfig=OperationTree.generateConfig(context);
        this.showTextPane.setText(generateConfig);
    }

    public boolean close(){
        return true;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        showTextPane = new javax.swing.JTextPane();
        runButton = new javax.swing.JButton();
        warnLabel = new javax.swing.JLabel();

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        showTextPane.setName("showTextPane"); // NOI18N
        jScrollPane1.setViewportView(showTextPane);

        runButton.setText("Run");
        runButton.setName("runButton"); // NOI18N
        runButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                runButtonActionPerformed(evt);
            }
        });

        warnLabel.setText("Generator configuration info");
        warnLabel.setName("warnLabel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(warnLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 446, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
                        .addComponent(runButton)
                        .addGap(197, 197, 197))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 754, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(runButton)
                    .addComponent(warnLabel))
                .addGap(34, 34, 34))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void runButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runButtonActionPerformed
        
        warn(OperationTree.mybatisGenerate(context));
        
    }//GEN-LAST:event_runButtonActionPerformed

    private void warn(String s){
        this.warnLabel.setText("<html><head></head><body><font color='red'>"+s+"</font></body></html>");
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton runButton;
    private javax.swing.JTextPane showTextPane;
    private javax.swing.JLabel warnLabel;
    // End of variables declaration//GEN-END:variables

}
